<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="共享盘名称" prop="workShop">-->
<!--        <el-select v-model="queryParams.workShop" placeholder="请选择共享盘" clearable-->
<!--                   @keyup.enter.native="handleQuery">-->
<!--          <el-option-->
<!--            v-for="item in workShopList"-->
<!--            :key="item.value"-->
<!--            :label="item.label"-->
<!--            :value="item.value"/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="读取时间" prop="readTime">
        <el-date-picker
          v-model="readTime"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions" @keyup.enter.native="handleQuery">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" border :data="fileInfoList">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-descriptions v-for="(batch, index) in props.row.batches" :key="index"
                           :title="'药品批次信息' + (index + 1)"
                           style="margin-left: 20px">
            <!-- 循环生成el-descriptions-item -->
            <el-descriptions-item label="药品批号">
              {{ batch.batchNo }}
            </el-descriptions-item>
            <el-descriptions-item label="生产日期">
              {{ batch.madeDate }}
            </el-descriptions-item>
            <el-descriptions-item label="有效期至">
              {{ batch.validateDate }}
            </el-descriptions-item>
            <el-descriptions-item label="车间信息">
              {{ batch.workshop }}
            </el-descriptions-item>
            <el-descriptions-item label="生产线名称">
              {{ batch.lineName }}
            </el-descriptions-item>
            <el-descriptions-item label="生产线管理员">
              {{ batch.lineManager }}
            </el-descriptions-item>
            <el-descriptions-item label="实际生产数量">
              {{ batch.realCount }}
            </el-descriptions-item>
          </el-descriptions>
        </template>
      </el-table-column>
      <el-table-column label="文件名" align="center" prop="fileName"/>
      <el-table-column label="药品子类编码" align="center" prop="subTypeNo"/>
      <el-table-column label="包装规格" align="center" prop="packageSpec"/>
      <el-table-column label="包装比例" align="center" prop="bili"/>
      <!--      <el-table-column label="抓取时间" align="center" prop="fetchTime" :formatter="formatDate"/>-->
      <el-table-column label="读取时间" align="center" prop="writeBackTime" :formatter="formatDate"/>
      <el-table-column label="共享盘信息" align="center" prop="workshop"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listFileInfos, queryWorkShop
} from "@/api/msfx/fileTransfer/fileInfos";

export default {
  name: "fileInfos",
  dicts: ['host_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 关联关系表格数据
      fileInfoList: [],
      //工厂信息
      factoryNameOptions: [],
      //车间信息
      workShopList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      readTime: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workShop: ''
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ipAddress: [
          {type: 'string', required: true, message: 'IP地址不能为空', trigger: 'blur'}
        ],
        path: [
          {required: true, message: "文件夹路径不能为空", trigger: "blur"}
        ],
        userName: [
          {required: true, message: "访问账号不能为空", trigger: "blur"}
        ],
        password: [
          {required: true, message: "访问密码不能为空", trigger: "blur"}
        ],
        type: [
          {required: true, message: "主机类型", trigger: "change"}
        ],
        pcName: [
          {required: true, message: "主机名称不能为空", trigger: "blur"}
        ]
      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
    };
  },
  created() {
    this.getList();
    this.getFactoryList();
    this.getWorkShopList()
  },
  methods: {
    formatDate(row, column, cellValue, index) {
      const daterc = row[column.property]
      if (daterc == null || daterc === "") return "";
      var date = new Date(daterc)
      var year = date.getFullYear()
      var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
      var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
      var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
      var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
      var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
    },
    /** 查询共享文件夹配置列表 */
    getList() {
      this.loading = true;
      let date = this.readTime;
      if (date !== null && typeof date !== "undefined") {
        let startTime = date[0];
        let endTime = date[1];

        this.queryParams.beginTime = startTime;
        this.queryParams.endTime = endTime;
      }
      listFileInfos(this.queryParams).then(response => {
        this.fileInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        ipAddress: null,
        path: null,
        userName: null,
        password: null,
        type: null,
        pcName: null
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    showDetail(row) {

    },
    /**
     * 查询工厂信息列表
     */
    getFactoryList() {
      Fusion_Manufacturer_Info().then(response => {
        this.factoryNameOptions = response.data;
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('fileTransfer/ShareFolders/export', {
        ...this.queryParams
      }, `ShareFolders_${new Date().getTime()}.xlsx`)
    },

    /**
     * 获取车间信息
     */
    getWorkShopList() {
      queryWorkShop(this.queryParams.businessEntId).then(response => {
        this.workShopList = response.data;
      });
    }
  }
};
</script>
